//
//  VehicleTableViewCell.m
//  HondaPro_2
//
//  Created by ht on 13-7-15.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "VehicleTableViewCell.h"

@implementation VehicleTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setUI];

    }
    return self;
}
-(void)setDict:(NSDictionary *)dict
{
    _dict=dict;
    int i=0;
    for (UILabel*label in self.contentView.subviews) {
        switch (i) {
            case 0:
                //作业单号
                label.text = dict[@"JOB_SHEET_ID"];
                break;
            case 1:
                //车牌号
                 label.text = dict[@"PLATE_NUMBER"];
                break;
            case 2:
                //车架号
                 label.text = dict[@"VIN"];
                break;
            case 3:
                //获取车型
                label.text=[self getchexing:dict[@"MODEL"]];
                break;
            case 4:
                //获取车主
                 label.text = dict[@"CUSTOMER_NAME"];
                break;
            case 5:
                //服务专员
                 label.text =[self getEVALUATOR_NAME:dict[@"EVALUATOR_NAME"]];
                break;
           
                
            default:
                break;
        }
        i++;
    }
}
-(NSString *)getchexing:(NSString*)sender{
    NSArray *zidianArr=[self readershuDICimform][@"MODEL"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"MODEL_CODE"] isEqualToString:sender]) {
            return dic[@"MODEL_NAME"];
        }
    }
    return nil;
}
-(NSString *)getEVALUATOR_NAME:(NSString*)sender{
    NSArray *zidianArr=[self readershuDICimform][@"SERVICE_ADVISOR"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"CODE"] isEqualToString:sender]) {
            return dic[@"NAME"];
        }
    }
    return nil;
}
-(void)setUI{
    for (int i=0; i<6; i++) {
        UILabel*label = [[UILabel alloc]init];
        [label setBackgroundColor:[UIColor clearColor]];
        [label setTextColor:[UIColor grayColor]];
        label.font = [UIFont fontWithName:@"ArialMT" size:13];
        [label setTextAlignment:NSTextAlignmentCenter];
        label.lineBreakMode = NSLineBreakByWordWrapping;
        label.numberOfLines = 0;
        [self.contentView addSubview:label];
    }
    
}
-(NSMutableDictionary *)readershuDICimform
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *str=[path stringByAppendingPathComponent:@"Dic.text"];
    dic=[NSMutableDictionary dictionaryWithContentsOfFile:str];
    //nslog(@"%@",dic);
    return dic;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat w=self.mj_w/self.contentView.subviews.count;
    int i=0;
    for (UILabel*label in self.contentView.subviews) {
        label.frame=CGRectMake(i*w, 0, w, self.contentView.mj_h);
        i++;
    }
}

@end
